/*
 *  atBudget Personal Finance Management application
 *
 *  Copyright 2011, Ilia Frenkel <frenkel.ilia@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
	Edit currency dialogue.
 */
Ext.define('ATB.view.currency.Edit', {
	extend: 'Ext.window.Window',
	alias : 'widget.currencyedit',

	title : 'Edit Currency',
	layout: 'fit',
	autoShow: true,
	resizable: false,
	modal: true,
	width: 370,
	
	initComponent: function() {
		this.items = [
			{
				xtype: 'form',
				bodyPadding: 10,
				border: false,
				submitEmptyText: false,
				defaults: {
					margin: '10 0'
				},
				items: [{
						xtype: 'fieldcontainer',
						anchor: '100%',
						fieldLabel: 'Description',
						labelWidth: 80,
						defaultType: 'textfield',
						layout: 'hbox',
						defaults: {
							flex: 1,
							margin: '0 1',
							labelSeparator: '',
							labelStyle: 'font-size: 80%'
						},
						fieldDefaults: {
							msgTarger: 'under',
							labelAlign: 'top'
						},
						items: [{
							tabIndex: 10,
							flex: 3,
							name : 'name',
							fieldLabel: 'Name',
							allowBlank: false
						}, {
							tabIndex: 20,
							flex: 1,
							name : 'code',
							fieldLabel: 'Code',
							allowBlank: false,
							minLength: 3,
							maxLength: 3,
							enforceMaxLength: true,
							vtype: 'alpha',
							vtypeText: 'This field must be exactly 3 characters'+
								' ISO code for the currency.',
							emptyText: 'ISO 4217 code.',
							blankText: 'This field must be exactly 3 characters'+
								' ISO code for the currency.',
							minLengthText: 'This field must be exactly 3 '+
								'characters ISO code for the currency.',
							maxLengthText: 'This field must be exactly 3 '+
							'characters ISO code for the currency.'
						}]
					}, {
						xtype: 'fieldcontainer',
						anchor: '100%',
						fieldLabel: 'Symbols',
						labelWidth: 80,
						defaultType: 'textfield',
						layout: 'hbox',
						defaults: {
							flex: 1,
							margin: '0 1',
							labelSeparator: '',
							labelStyle: 'font-size: 80%'
						},
						fieldDefaults: {
							msgTarger: 'under',
							labelAlign: 'top'
						},
						items: [{
							fieldLabel: 'Prefix',
							tabIndex: 30,
							name: 'prefix'
						}, {
							fieldLabel: 'Suffix',
							tabIndex: 40,
							name: 'suffix'
						}]
					}, {
						xtype: 'fieldcontainer',
						anchor: '100%',
						fieldLabel: 'Format',
						labelWidth: 80,
						defaultType: 'textfield',
						layout: 'hbox',
						defaults: {
							flex: 1,
							margin: '0 1',
							labelSeparator: '',
							labelStyle: 'font-size: 80%'
						},
						fieldDefaults: {
							msgTarger: 'under',
							labelAlign: 'top'
						},
						items: [{
							fieldLabel: 'Thousands',
							tabIndex: 50,
							name: 'thousands'
						}, {
							fieldLabel: 'Decimal',
							tabIndex: 60,
							name: 'decimal'
						}, {
							xtype: 'numberfield',
							tabIndex: 70,
							fieldLabel: 'Precision',
							name: 'precision',
							allowDecimals: false,
							minValue: 0
						}]
					}, {
						xtype: 'displayfield',
						anchor: '100%',
						fieldLabel: 'Example',
						labelWidth: 80,
						name: 'examplefmt'
				}]
			}
		];

		this.buttons = [
			{
				text: 'Save',
				tabIndex: 80,
				action: 'save'
			},
			{
				text: 'Cancel',
				tabIndex: 90,
				scope: this,
				handler: this.close
			}
		];

		this.on('show', function(wnd) {
			wnd.down("textfield[name=name]").focus(true, 200);
		});
		
		this.callParent(arguments);
	}
});